<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head lang="en">
    <th:block th:include="include :: header('权限设置')"/>
</head>
<body style="margin: auto">
<script src="/js/layui-xtree.js"></script>
<form class="layui-form">
    <div id="xtree1" class="xtree_contianer"></div>
</form>

<th:block th:include="include :: footer"/>
<script type="text/javascript">
    id = parent.selRoleId;
    var xtree;
    //layui 的 form 模块是必须的
    layui.use(['form'], function () {
        var form = layui.form;

        //1、最基础的用法 - 直接绑定json
        xtree = new layuiXtree({
            elem: 'xtree1'   //(必填) 放置xtree的容器，样式参照 .xtree_contianer
            , form: form     //(必填) layui 的 from
            , data: '/sysUser/treeResource.json?id=' + id    //(必填) json数据
            , ckall: true
            , isopen: false
        });
    });

    function ApplicationSave() {
        //从父层获取值，json是父层的全局js变量。eval是将该string类型的json串变为标准的json串
        var str1 = "";
        $("input:checkbox[class='layui-xtree-checkbox']:checked").each(function (i) {
            str1 += $(this).val() + ",";
        });

        $.ajax({
            async: false,
            url: "/sysUser/setRole.json",
            type: "POST",
            data: {"str": str1, "roleId": id},
            dataType: "json",
            success: function (data) {
                parent.layer.closeAll();
                parent.layer.alert(data.info);

            }
        });
    }


    function ApplicationSaves() {

        var oCks = xtree.GetAllCheckBox(); //这是方法

        for (var i = 0; i < oCks.length; i++) {
            console.log(oCks[i].value);
        }
    }
</script>
<script type="text/javascript">

</script>

</body>
</html>